// pages/search/index.js
import { request } from '../../request/index.js';
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods:[],
    isFocus:false,
    inputValue:''
  },
  TimeId:-1,
  handleInput(e){
    const {value}=e.detail;
    if(!value.trim()){
      // 不合法
      this.setData({
        goods:[],
        isFocus:false
      })
      return;
    }
    this.setData({
      isFocus:true
    })
    clearTimeout(this.TimeId);
    this.TimeId=setTimeout(()=>{
      this.qsearch(value)
    },1000)
   
  },
  // 发送请求
  async qsearch(query){
    const res=await request({url:'/goods/qsearch',data:{query}});
    console.log(res);
    this.setData({
      goods:res
    })
  },
  handleCancle(){
    this.setData({
      inputValue:'',
      isFocus:false,
      goods:[]
    })
  }
})